package com.example.service.impl.institutioncare.fuwuxinxi;

import com.example.bean.configuration.zhibiaosystem.XzLiebiao;
import com.example.bean.institutioncare.fuwuxinxi.FuWuXinXi;
import com.example.bean.institutioncare.fuwuxinxi.FuWuXinXiVo;
import com.example.mapper.institutioncare.fuwuxinxi.FuWuXinXiMapper;
import com.example.service.institutioncare.fuwuxinxi.FuWuXinXiService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class FuWuXinXiServiceImpl implements FuWuXinXiService {

    @Autowired
    FuWuXinXiMapper fuWuXinXiMapper;

    @Override
    public PageInfo<FuWuXinXi> pagefuwuxinxi(FuWuXinXiVo fuWuXinXiVo) {
        PageHelper.startPage(fuWuXinXiVo.getDqNum(),fuWuXinXiVo.getXsNum());
        PageInfo page = new PageInfo(fuWuXinXiMapper.pagefuwuxinxi(fuWuXinXiVo));
        return page;
    }

    @Override
    @Transactional
    public Integer addFuWuXinXi(FuWuXinXi fuWuXinXi) {
        Integer addfuwu = fuWuXinXiMapper.addFuWuXinXi(fuWuXinXi);
        System.out.println("获取id："+fuWuXinXi.getNoid());
        if (addfuwu > 0){
            for (String noid : fuWuXinXi.getJigoutigong()){
                fuWuXinXiMapper.addzhongjian(fuWuXinXi.getNoid(),noid);
            }
        }
        return addfuwu;
    }

    @Override
    public List<XzLiebiao> listzhibiao() {
        return fuWuXinXiMapper.listzhibiao();
    }

    @Override
    public FuWuXinXi huixianfuwuxinxi(String noid) {
        //回显主表信息
        FuWuXinXi fuWuXinXi = fuWuXinXiMapper.huixianfuwuxinxi(noid);
        //回显出中间表服务信息
        fuWuXinXi.setJigoutigong(fuWuXinXiMapper.huixianzhongjian(noid));
        return fuWuXinXi;
    }

    @Override
    public Integer xiugaifuwu(FuWuXinXi fuWuXinXi) {
        Integer xiu = fuWuXinXiMapper.xiugaifuwu(fuWuXinXi);
//        String fuwu = fuWuXinXiMapper.chafuwu(fuWuXinXi);
        if (xiu > 0){
            fuWuXinXiMapper.shanfuwu(fuWuXinXi.getNoid());
            for (String noid : fuWuXinXi.getJigoutigong()){
                fuWuXinXiMapper.addzhongjian(fuWuXinXi.getNoid(),noid);
            }
        }
        return xiu;
    }

    @Override
    public Integer shanchufuwu(List<String> ids) {
        Integer shan = fuWuXinXiMapper.piliangshan(ids);
        if (shan > 0){
            FuWuXinXi fuwuxinxi = new FuWuXinXi();
            fuWuXinXiMapper.shanfuwu(fuwuxinxi.getNoid());
        }
        return shan;
    }
}
